package com.uni.db;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.transaction.annotation.Transactional;

import com.uni.domain.File;
import com.uni.domain.Identifiable;

@Transactional
public class GenericServiceImpl<T extends Identifiable> implements GenericService {

    GenericDao dao;

    @Transactional
    public T get(Long id) {
        return (T) dao.get(id);
    }

    @Transactional
    public void save(Identifiable obj) {
        dao.save(obj);
    }

    @Transactional
    public void delete(Identifiable obj) {
        dao.delete(obj);
    }

    @Transactional(readOnly = true)
    public List<T> listAll() {
        return (List<T>) dao.listAll();
    }

    @Transactional(readOnly = true)
    public int countAll() {
        return dao.countAll();
    }

    public void evict(Identifiable obj) {
        dao.evict(obj);
    }

    public void flushSession() {
        dao.flushSession();
    }

    public void clearSession() {
        dao.clearSession();
    }

    public Session getSession() {
        return dao.getSession();
    }

    public void setDao(GenericDao dao) {
        this.dao = dao;
    }

}
